home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / ppl4c10.zip / DIR_IO.C < prev    next >
Text File  |  1995-02-06  |  2KB  |  92 lines

  1. /* dir_io.h */
  2.  
  3. #include <stdio.h>
  4. #include <dos.h>
  5. #include <string.h>
  6.  
  7. #include "dir_io.h"
  8.  
  9. #define FALSE 0
  10. #define TRUE !FALSE
  11.  
  12. #define BYTE unsigned char
  13. #define WORD unsigned int
  14.  
  15. typedef struct DTAbufferType
  16. {BYTE Reserved[21];
  17.  BYTE Attribute;
  18.  WORD Time;
  19.  WORD Date;
  20.  long Size;
  21.  BYTE Name[13];
  22.  BYTE Junk[85];
  23. } DTAbufferType;
  24.  
  25. static DTAbufferType DTA1buffer;
  26. static DTAbufferType DTA2buffer;
  27.  
  28. static void dosSetDTA(int which)
  29. {union REGS reg;
  30.  switch(which)
  31.    {case 1:
  32.       reg.x.dx = (WORD) (&DTA1buffer);
  33.       break;
  34.     case 2:
  35.       reg.x.dx = (WORD) (&DTA2buffer);
  36.       break;
  37.    }
  38.  reg.h.ah = 0x1A;
  39.  int86(0x21, ®, ®);
  40. }
  41.  
  42. static int dosFindFirst(char *FileSpec)
  43. {union REGS reg;
  44.  reg.x.dx = (WORD) FileSpec;
  45.  reg.h.ah = 0x4e;
  46.  reg.x.cx = 0;
  47.  int86(0x21, ®, ®);
  48.  if(reg.x.cflag) return FALSE;
  49.  return TRUE;
  50. }
  51.  
  52. static int dosFindNext(void)
  53. {union REGS reg;
  54.  reg.h.ah = 0x4f;
  55.  int86(0x21, ®, ®);
  56.  if(reg.x.cflag) return FALSE;
  57.  return TRUE;
  58. }
  59.  
  60. /*** PUBLIC ***/
  61.  
  62. int FindFirst(char *Specifier,char *Name,long *Size)
  63. {dosSetDTA(1);
  64.  if(dosFindFirst(Specifier))
  65.    {if(Name) strncpy(Name,DTA1buffer.Name,13);
  66.     if(Size) *Size = DTA1buffer.Size;
  67.     return TRUE;
  68.    }
  69.  return FALSE;
  70. }
  71.  
  72. int FindNext(char *Name,long *Size)
  73. {dosSetDTA(1);
  74.  if(dosFindNext())
  75.    {strncpy(Name,DTA1buffer.Name,13);
  76.     if(Size) *Size = DTA1buffer.Size;
  77.     return TRUE;
  78.    }
  79.  return FALSE;
  80. }
  81.  
  82. int FileSDT(char *Name,long *Size,WORD *Date,WORD *Time)
  83. {dosSetDTA(2);
  84.  if(dosFindFirst(Name))
  85.    {*Size = DTA2buffer.Size;
  86.     *Date = DTA2buffer.Date;
  87.     *Time = DTA2buffer.Time;
  88.     return TRUE;
  89.    }
  90.  return FALSE;
  91. }
  92.